package com.neu.question.form;

import com.neu.question.domain.EndUserInfo;
import com.neu.question.domain.UserInfo;
import lombok.Data;

import java.text.SimpleDateFormat;
import java.util.Date;

@Data
public class EndUserForm {
    private String username;
    private String password;
    private String phoneNum;
    private String opusername;
    private Date startTime;
    private Date stopTime;
    private String tenantsId;
    private String questionnaireNum;
    private String start;
    private String stop;
    private String id;

    public EndUserForm create (UserInfo userInfo, String tenantsId, String questionnaireNum) {
        EndUserForm endUserForm = new EndUserForm();
        endUserForm.setUsername(userInfo.getUsername());
        endUserForm.setPassword(userInfo.getPassword());
        endUserForm.setPhoneNum(userInfo.getPhoneNum());
        endUserForm.setOpusername(userInfo.getCreatedBy());
        endUserForm.setTenantsId(tenantsId);
        endUserForm.setQuestionnaireNum(questionnaireNum);
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date d = userInfo.getStartTime();
        d.setTime(d.getTime() - 8*60*60*1000);
        String dateString = sdf.format(d);
        d = userInfo.getStopTime();
        d.setTime(d.getTime() - 8*60*60*1000);
        String date = sdf.format(d);
        endUserForm.setStart(dateString);
        endUserForm.setStop(date);

        endUserForm.setStartTime(userInfo.getStartTime());
        endUserForm.setStopTime(userInfo.getStopTime());

        return endUserForm;
    }
}
